﻿<form method="post">
    @Html.AntiForgeryToken()
    <div class="toolbar" style="margin-top:0; border-top:none 0; position:fixed; top:0; left:0; right:0; margin-left:auto; z-index:999; width:100%; margin-right:auto;">
        <a href="javascript:void(0);" onclick="window.location='@ViewData["prevUrl"]';return false;"><i class="fa fa-mail-reply"></i><label>返回</label></a>
        <span class="toolbarsplit">&nbsp;</span>
        <a href="javascript:void(0);" onclick="checkform(this);"><i class="fa fa-save"></i><label>保存设置</label></a>
    </div>
    <table id="treeTable1" style="width:100%; margin-top:37px;" class="listtable">
        <thead>
            <tr>
                <th style="width:26%;">标题</th>
                <th style="width:7%;">图标</th>
                <th style="width:7%; text-align:center"><input type="checkbox" id="checkall" onclick="$('input[type=\'checkbox\']').prop('checked', this.checked);" /></th>
                <th style="width:40%;">按钮</th>
                <th style="width:20%">参数</th>
            </tr>
        </thead>
        <tbody>
            @Html.Raw(ViewData["tableHtml"])
        </tbody>
    </table>
</form>
<script type="text/javascript">
    var treeTable = new RoadUI.TreeTable();
    $(function () {
        treeTable.init({ id: "treeTable1" });
        if ($(":checked[type='checkbox'][name='menuid']").size() > 0) {
            $("#checkall").prop('checked', true);
        }
    });
    function checkform(but) {
        var f = document.forms[0];
        var o = RoadUI.Core.serializeForm($(f));
        var click = RoadUI.Core.disableda(but);
        $.ajax({
            url: "SaveSetMenu@(Html.Raw(ViewData["queryString"]))", data: o, type: "post", success: function (text) {
                if (RoadUI.Core.checkLogin(text, false)) {
                    alert(text);
                }
                window.location = window.location;
            }
        });
    }
    function appboxclick(box) {
        if (!box.checked) {
            $(box).parent().next().find("input[type='checkbox']").prop('checked', box.checked);
            treeTable.childs = new Array();
            var allChilds = treeTable.getAllChilds($(box).parent().parent());
            for (var i = 0; i < allChilds.length; i++) {
                $("input[type='checkbox']", allChilds[i]).prop('checked', box.checked);
            }
        }
        else {
            var treetable = new RoadUI.TreeTable();
            treetable.parents = [];
            treetable.getAllParents($(box).parent().parent());
            for (var i = 0; i < treetable.parents.length; i++) {
                $("input[type='checkbox'][name='menuid']", treetable.parents[i]).prop('checked', true);
            }
            treeTable.childs = new Array();
            var allChilds = treeTable.getAllChilds($(box).parent().parent());
            for (var i = 0; i < allChilds.length; i++) {
                $("input[type='checkbox']", allChilds[i]).prop('checked', box.checked);
            }
        }
    }
    function buttonboxclick(box) {
        if ($(":checked", $(box).parent()).size() > 0) {
            $(box).parent().prev().find("input[type='checkbox']").prop('checked', true);
        }
        else {
            //$(box).parent().prev().find("input[type='checkbox']").prop('checked', false);
        }
    }
</script>